package org.durandj.ystream.client.network.packetHandlers;

import org.durandj.ystream.client.YStreamClient;
import org.durandj.ystream.client.network.Packet;
import org.durandj.ystream.client.network.PacketHandler;
import org.durandj.ystream.client.network.Server;

/**
 * Handles the Ping packet. This handler basically echoes the packet back to the server that sent it.
 * 
 * @author durandj
 * @version 1.0
 *
 */
public class PingPacketHandler extends PacketHandler
{
	/**
	 * Creates a packet handler for the ping opcode.
	 */
	public PingPacketHandler()
	{
		super();
	}
	
	/* (non-Javadoc)
	 * @see org.durandj.ystream.client.network.PacketHandler#handlePacket(org.durandj.ystream.client.network.Packet)
	 */
	@Override
	protected void handlePacket(Packet packet)
	{
		Server server = YStreamClient.getClient().getNetworkDaemon().getServer();
		Packet echoPacket = new Packet(packet.getPriority(),
		                               packet.getOpcode(),
		                               packet.getSource(),
		                               packet.getTarget(),
		                               packet.getContents());
		server.getPacketSender().sendPacket(echoPacket);
	}
}
